/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package unilearn.dao.hibernate;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import unilearn.dao.MarkSheetDAO;
import unilearn.vo.MarkSheet;

/**
 *
 * @author Ming
 */
public class MarkSheetDAOImpl extends HibernateDAO implements MarkSheetDAO {

    public MarkSheetDAOImpl() {
        super();
    }

    public MarkSheetDAOImpl(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    @Override
    public void setSessionFactory(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }

    @Override
    public List<MarkSheet> getAll() throws Exception {
        return super.getAll(MarkSheet.class.getName());
    }

    @Override
    public MarkSheet get(int id) throws Exception {
        Session s = sessionFactory.openSession();
        Transaction t = s.beginTransaction();

        try {
            Query query = s.createQuery("from " + MarkSheet.class.getName() + " a where a.id = " + id);
            List<MarkSheet> as = query.list();
            if ((as == null) || (as.isEmpty())) {
                return null;
            }

            return as.get(0);
        } finally {
            t.commit();
            s.close();
        }
    }

    @Override
    public List<MarkSheet> find(MarkSheet markSheet) throws Exception {
        return (List<MarkSheet>) super.find(markSheet);
    }

    @Override
    public MarkSheet insert(MarkSheet markSheet) throws Exception {
        super.insert(markSheet);
        return markSheet;
    }

    @Override
    public MarkSheet update(MarkSheet markSheet) throws Exception {
        super.update(markSheet);
        return markSheet;
    }

    @Override
    public void delete(MarkSheet markSheet) throws Exception {
        super.delete(markSheet);
    }
}